
/**
 * Copyright 2009 cestum.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
package org.waveprotocol.wave.model.util {
/**
 * An ordered pair of typed objects.
 */
public class Pair {
	
	public static function of(a:Object, b:Object):Pair {
		return new Pair(a, b);
	}
	
	public static function ofPair(p:Pair):Pair {
		return new Pair(p.first, p.second);
	}
	
	public var first:Object;
	public var second:Object;
	
	public function Pair(first:Object, second:Object) {
		this.first = first;
		this.second = second;
	}
	public function getFirst():Object {
		return first;
	}
	
	public function getSecond():Object {
		return second;
	}
	
	public final function equals(o:Object):Boolean {
		if (o == null) return false;
		if (o == this) return true;
		if (o instanceof Pair) {
			var p:Pair= Pair(o);
			return (p.first == first && p.second == second);
		}
		return false;
	}
	
	public final function hashCode():int {
		return (first == null ? 0: first.hashCode()) + 37* (second == null ? 0: second.hashCode());
	}
	
	public function toString():String {
		return "(" + first + "," + second + ")";
	}
}
}